﻿package com.mcflywzx.airhockey.util;

import com.mcflywzx.airhockey.AirHockeyRenderer;

import android.content.Context;
import android.content.pm.ConfigurationInfo;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.widget.Toast;
import static android.widget.Toast.makeText;;

public class Tools {
	public static final boolean CanLog  = true;
	
	public static float clamp(float var, float min, float max) {
		return Math.min(max, Math.max(var, min));
	}
	
	public static boolean CanGLES2(ConfigurationInfo configurationInfo) {
		return
	        	configurationInfo.reqGlEsVersion >= 0x20000
	        		|| (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1
	        		 && (Build.FINGERPRINT.startsWith("generic")
	        		  || Build.FINGERPRINT.startsWith("unknow")
	        		  || Build.MODEL.contains("google_sdk")
	        		  || Build.MODEL.contains("Emulator")
	        		  || Build.MODEL.contains("Android SDK built for x86")));
	}

	public static void ToastLog(final Context co, String log) {
		
		Handler h = new Handler(Looper.getMainLooper());
		class toastRunnable implements Runnable{
			final String log;
			
			public toastRunnable(String log) {
				this.log = log;
			}
			@Override
			public void run() {
				// TODO Auto-generated method stub
				Toast.makeText(co, log, Toast.LENGTH_SHORT).show();
			}
		}
		h.post(new toastRunnable(log));
		
	}

}